<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : up_price.manage.php   FILE_PATH : E:\web\mulitishop\system\up_price.manage.php
 * .自动加价管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 
 * @package 
 * @subpackage 
 * @version Fri Dec 07 15:19:10 CST 2007
 */

require_once("../global.inc.php");

class SysUpPriceManage extends SystemFrameWork{
	/**
	 * 加价操作对象
	 * 
	 * @var obj
	 */
	var $obj_up_price;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	
	function main(){
		/**
		 * 创建加价操作对象
		 */
		if (!is_object($this->obj_up_price)){
			require_once("up_price.class.php");
			$this->obj_up_price = new UpPriceClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");
		
		/**
		 * 语言包
		 */
		$this->getlang("upprice");
		
		switch ($this->_input['action']){
			case "add":
				$this->_add_upprice();
				break;
			case "modify":
				$this->_get_price_info();
				break;
			case "modifysave":
				$this->_update_price_info();
				break;
			case "del":
				$this->_del_price_info();
				break;
			default:
				$this->_list_upprice();
				break;
		}
	}
	
	/**
	 * 得到加价列表
	 */
	function _list_upprice()
	{
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		/**
		 * 取得加价列表
		 */
		$obj_page->pagebarnum(20);
		
		$price_list = $this->obj_up_price->getUpPriceList($obj_page);
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		$this->output("page_list", $page_list);
		$this->output('price_list',$price_list);
		$this->showpage('sys_up_price.manage');
	}
	
	/**
	 * 新增价格增幅
	 */
	function _add_upprice(){
		
		$error = $this->_check_info();
		
		if($error != ""){
			echo $error;
			exit;			
		}else{
			/*检查新增区间是否与已有区间重复*/
			$result = $this->obj_up_price->checkRepeatPrice($this->_input);
			if (false == $result){
				echo "新增区间与已有区间重复";
				exit;
			}else {
				$result = $this->obj_up_price->addUpPrice($this->_input);
				if (false !=$result){
					echo "ok";exit;
				}				
				echo "no ok";exit;
			}
		}
	}
	
	/**
	 * 取指定ID的增幅信息
	 */
	function _get_price_info(){
		
		$price_array = $this->obj_up_price->getPriceById($this->_input["i_id"]);
		$this->output('price_array',$price_array);
		$this->showpage('sys_up_price.modi');
	}
	
	/**
	 * 保存修改过的增幅信息
	 */
	function _update_price_info(){
		
		$error = $this->_check_info('u_');
		
		if($error != ""){
			echo $error;
			exit;			
		}else{
			/*检查区间是否与已有区间重复*/
			$result = $this->obj_up_price->checkRepeatPrice($this->_input,'u_',1,$this->_input['i_id']);
			if (false == $result){
				echo "区间与已有区间重复";
				exit;
			}else {
				$result = $this->obj_up_price->updateUpPrice($this->_input);
				if (false !=$result){
					echo "ok";exit;
				}
				echo "no ok";exit;
			}
		}
	}
	
	/**
	 * 检查输入内容
	 */
	function _check_info($type=''){
	
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input[$type."txt_i_low"], "require"=>"true", "validator"=>"Currency", "message"=>$this->_lang['errLowEmpty']),
		array("input"=>$this->_input[$type."txt_i_high"], "require"=>"true", "validator"=>"Currency", "message"=>$this->_lang['errHighEmpty']),
		array("input"=>$this->_input[$type."txt_i_low"], "require"=>"false", "validator"=>"Compare", "operator"=>"<","to"=>$this->_input[$type."txt_i_high"], "message"=>$this->_lang['errEqual'],"result"=>true),
		array("input"=>$this->_input[$type."txt_increment"], "require"=>"true", "validator"=>"Integer", "message"=>$this->_lang['errIncrement'],"result"=>true));
		/**/
		$error = $this->objvalidate->validate();	
		return $error;
	}
	
	/**
	 * 删除增幅信息
	 */
	function _del_price_info(){
		$this->obj_up_price->delUpPrice($this->_input['i_id']);
		echo 'ok';
	}
}
$up_price_manage = new SysUpPriceManage();
$up_price_manage->main();
unset($up_price_manage);
?>